﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Collections.ObjectModel;

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;

namespace RSD.ViewModel
{
    using Data;
    using Messages;

    public class CreatePositionViewModel : ViewModelBase
    {
        private readonly IPositionRepository positionRepository;
        private readonly AdminViewModel adminModel;
        private readonly RelayCommand createPositionCommand;

        private string positionName;
        private int x;
        private int y;
        private int z;
        private int pitch;
        private int roll;

        public CreatePositionViewModel(IPositionRepository positionRepository, AdminViewModel adminModel)
        {
            this.adminModel = adminModel;
            this.positionRepository = positionRepository;

            this.createPositionCommand = new RelayCommand(CreatePositionExecute);
        }

        public string PositionName
        {
            get
            {
                return positionName;
            }
            set
            {
                positionName = value;
                RaisePropertyChanged("PositionName");
            }
        }

        public int X
        {
            get
            {
                return x;
            }
            set
            {
                x = value;
                RaisePropertyChanged("X");
            }
        }

        public int Y
        {
            get
            {
                return y;
            }
            set
            {
                y = value;
                RaisePropertyChanged("Y");
            }
        }

        public int Z
        {
            get
            {
                return z;
            }
            set
            {
                z = value;
                RaisePropertyChanged("Z");
            }
        }

        public int Pitch
        {
            get
            {
                return pitch;
            }
            set
            {
                pitch = value;
                RaisePropertyChanged("Pitch");
            }
        }

        public int Roll
        {
            get
            {
                return roll;
            }
            set
            {
                roll = value;
                RaisePropertyChanged("Roll");
            }
        }

        public ICommand CreatePositionCommand
        {
            get
            {
                return createPositionCommand;
            }
        }

        private void CreatePositionExecute()
        {
            var position = new Position()
            {
                X = x,
                Y = y,
                Z = z,
                Pitch = pitch,
                Roll = roll
            };

            Messenger.Default.Send(new PositionCreatedMessage(position));
        }
    }
}
